-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[staking] ActiveCandidate Exclude Candidate with Expired Endorsement #4062
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4062 +/- ##
==========================================
+ Coverage 75.38% 76.40% +1.02%
==========================================
Files 303 340 +37
Lines 25923 28984 +3061
==========================================
+ Hits 19541 22145 +2604
- Misses 5360 5734 +374
- Partials 1022 1105 +83 ☔ View full report in Codecov by Sentry. |
action/protocol/staking/protocol.go
Outdated
} | ||
// bucket is not endorsed to the candidate | ||
if !address.Equal(vb.Candidate, cand.Owner) { | ||
return false, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this happens, there must be something wrong with our implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, if clearing candidates is implemented after bucket endorsed to others.
action/protocol/staking/protocol.go
Outdated
// other error | ||
return false, err | ||
default: | ||
// endorsement does not exist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return false, nil
or return false, ErrNotExist
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is unexpected behaviours, should return error
action/protocol/staking/protocol.go
Outdated
// endorsement exists and expired before end of next epoch | ||
rp := rolldpos.MustGetProtocol(protocol.MustGetRegistry(ctx)) | ||
currentEpochNum := rp.GetEpochNum(srHeight) | ||
if endorse.Status(rp.GetEpochLastBlockHeight(currentEpochNum+1)) == EndorseExpired { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you elaborate it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is checking that only nodes whose endorsement have not expired before the end of the next epoch will be considered as consensus nodes. This ensures that self-stake bucket is locked when participate in consensus, which facilitates the introduction of penalty mechanisms in the future.
action/protocol/staking/protocol.go
Outdated
@@ -513,6 +509,7 @@ func (p *Protocol) isActiveCandidate(ctx context.Context, csr CandidateStateRead | |||
return false, err | |||
default: | |||
// endorsement does not exist | |||
return false, errors.New("endorsement does not exist") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
global variable
action/protocol/staking/protocol.go
Outdated
vb, err := csr.getBucket(cand.SelfStakeBucketIdx) | ||
if err != nil { | ||
if errors.Is(err, state.ErrStateNotExist) { | ||
return false, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SelfStakeBucketIndex shouldn't be an invalid one, so we may always return false, err
action/protocol/context.go
Outdated
@@ -116,6 +116,7 @@ type ( | |||
SharedGasWithDapp bool | |||
ExecutionSizeLimit32KB bool | |||
UseZeroNonceForFreshAccount bool | |||
DisableDelegateEndorsement bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why DisableDelegateEndorsement
not EnableDelegateEndorsement
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the default value for this bool represents the activated state of the new feature, while a default value for bool
in Go is false
.
@@ -492,7 +538,11 @@ func (p *Protocol) ActiveCandidates(ctx context.Context, sr protocol.StateReader | |||
} | |||
list[i].Votes.Add(list[i].Votes, contractVotes) | |||
} | |||
if list[i].SelfStake.Cmp(p.config.RegistrationConsts.MinSelfStake) >= 0 { | |||
active, err := p.isActiveCandidate(ctx, c, list[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are unactive cands included in L527?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two scenarios:
- The self-stake bucket has been unstaked.
- The endorsement has expired.
Both situations belong to a registered delegate, but they cannot participate in consensus due to a lack of staking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. It seems the state of candidates aren't tracked in the db(active/unactive). Pls add ur comments to explain why the list is filtered above L541
d646bb2
to
22da849
Compare
Quality Gate failedFailed conditions 4.6% Duplication on New Code (required ≤ 3%) |
if cand.SelfStake.Cmp(p.config.RegistrationConsts.MinSelfStake) < 0 { | ||
return false, nil | ||
} | ||
return true, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just return cand.SelfStake.Cmp(p.config.RegistrationConsts.MinSelfStake) >= 0, nil
action/protocol/staking/protocol.go
Outdated
} | ||
rp := rolldpos.MustGetProtocol(protocol.MustGetRegistry(ctx)) | ||
currentEpochNum := rp.GetEpochNum(srHeight) | ||
return csr.IsActiveCandidateAt(cand, rp.GetEpochLastBlockHeight(currentEpochNum+1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why should be currentEpochNum+1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refer to #4062 (comment)
if err != nil { | ||
return nil, err | ||
} | ||
if active { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from the usage here, it is checking current height, not currentEpochNum+1
height
return false, nil | ||
} | ||
esr := NewEndorsementStateReader(c.SR()) | ||
endorse, err := esr.Get(cand.SelfStakeBucketIdx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be guarded by hard-fork flag? before 1.14, no such thing as endorsement exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quality Gate failedFailed conditions |
Description
Since the
SelfStake
field of aCandidate
is not cleared when an endorsement expires, the currentActiveCandidate
function does not remove expired candidates. This PR is aimed at fixing this issue.Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Test Configuration:
Checklist: